package br.unipar.blog.view.action;

import java.util.Date;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;

public class JasperJsfUtils {
    
    public static void exportToPdf(JasperPrint jasperPrint, String filename) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = 
        (HttpServletResponse)facesContext.getExternalContext().getResponse();
        
        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition", 
                String.format("inline;filename=%s-%d.pdf",
                filename, new Date().getTime())
        );
        
        JasperExportManager.exportReportToPdfStream(
                jasperPrint, response.getOutputStream());
        facesContext.responseComplete();
    }
    
}
